package com.boot.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class TimeUtil {

    public String getNextMonth(String time) throws ParseException {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calc =Calendar.getInstance();
        calc.setTime(df.parse(time));
        //当前日期一个月后
        calc.add(Calendar.MONTH, 1);
        Date minDate = calc.getTime();
        String minDateStr = df.format(minDate);
        return minDateStr;
    }

    public String[] getNextMonth_for(String time, int size) throws ParseException {
        String[] strings = new String[size];
        if(size == 1){
            String s1 = getNextMonth(time);
            strings[0] = s1;
        }else if(size == 2){
            String s1 = getNextMonth(time);
            String s2 = getNextMonth(s1);
            strings[0] = s1;
            strings[1] = s2;
            return strings;
        }else if(size == 3){
            String s1 = getNextMonth(time);
            String s2 = getNextMonth(s1);
            String s3 = getNextMonth(s2);
            strings[0] = s1;
            strings[1] = s2;
            strings[2] = s3;
        }else if(size == 4){
            String s1 = getNextMonth(time);
            String s2 = getNextMonth(s1);
            String s3 = getNextMonth(s2);
            String s4 = getNextMonth(s3);
            strings[0] = s1;
            strings[1] = s2;
            strings[2] = s3;
            strings[3] = s4;
        }else if(size == 5){
            String s1 = getNextMonth(time);
            String s2 = getNextMonth(s1);
            String s3 = getNextMonth(s2);
            String s4 = getNextMonth(s3);
            String s5 = getNextMonth(s4);
            strings[0] = s1;
            strings[1] = s2;
            strings[2] = s3;
            strings[3] = s4;
            strings[4] = s5;
        }else if(size == 6){
            String s1 = getNextMonth(time);
            String s2 = getNextMonth(s1);
            String s3 = getNextMonth(s2);
            String s4 = getNextMonth(s3);
            String s5 = getNextMonth(s4);
            String s6 = getNextMonth(s5);
            strings[0] = s1;
            strings[1] = s2;
            strings[2] = s3;
            strings[3] = s4;
            strings[4] = s5;
            strings[5] = s6;
        }else if(size == 7){
            String s1 = getNextMonth(time);
            String s2 = getNextMonth(s1);
            String s3 = getNextMonth(s2);
            String s4 = getNextMonth(s3);
            String s5 = getNextMonth(s4);
            String s6 = getNextMonth(s5);
            String s7 = getNextMonth(s6);
            strings[0] = s1;
            strings[1] = s2;
            strings[2] = s3;
            strings[3] = s4;
            strings[4] = s5;
            strings[5] = s6;
            strings[6] = s7;
        }else if(size == 8){
            String s1 = getNextMonth(time);
            String s2 = getNextMonth(s1);
            String s3 = getNextMonth(s2);
            String s4 = getNextMonth(s3);
            String s5 = getNextMonth(s4);
            String s6 = getNextMonth(s5);
            String s7 = getNextMonth(s6);
            String s8 = getNextMonth(s7);
            strings[0] = s1;
            strings[1] = s2;
            strings[2] = s3;
            strings[3] = s4;
            strings[4] = s5;
            strings[5] = s6;
            strings[6] = s7;
            strings[7] = s8;
        }else if(size == 9){
            String s1 = getNextMonth(time);
            String s2 = getNextMonth(s1);
            String s3 = getNextMonth(s2);
            String s4 = getNextMonth(s3);
            String s5 = getNextMonth(s4);
            String s6 = getNextMonth(s5);
            String s7 = getNextMonth(s6);
            String s8 = getNextMonth(s7);
            String s9 = getNextMonth(s8);
            strings[0] = s1;
            strings[1] = s2;
            strings[2] = s3;
            strings[3] = s4;
            strings[4] = s5;
            strings[5] = s6;
            strings[6] = s7;
            strings[7] = s8;
            strings[8] = s9;
        }else if(size == 10){
            String s1 = getNextMonth(time);
            String s2 = getNextMonth(s1);
            String s3 = getNextMonth(s2);
            String s4 = getNextMonth(s3);
            String s5 = getNextMonth(s4);
            String s6 = getNextMonth(s5);
            String s7 = getNextMonth(s6);
            String s8 = getNextMonth(s7);
            String s9 = getNextMonth(s8);
            String s10 = getNextMonth(s9);
            strings[0] = s1;
            strings[1] = s2;
            strings[2] = s3;
            strings[3] = s4;
            strings[4] = s5;
            strings[5] = s6;
            strings[6] = s7;
            strings[7] = s8;
            strings[8] = s9;
            strings[9] = s10;
        }else if(size == 11){
            String s1 = getNextMonth(time);
            String s2 = getNextMonth(s1);
            String s3 = getNextMonth(s2);
            String s4 = getNextMonth(s3);
            String s5 = getNextMonth(s4);
            String s6 = getNextMonth(s5);
            String s7 = getNextMonth(s6);
            String s8 = getNextMonth(s7);
            String s9 = getNextMonth(s8);
            String s10 = getNextMonth(s9);
            String s11 = getNextMonth(s10);
            strings[0] = s1;
            strings[1] = s2;
            strings[2] = s3;
            strings[3] = s4;
            strings[4] = s5;
            strings[5] = s6;
            strings[6] = s7;
            strings[7] = s8;
            strings[8] = s9;
            strings[9] = s10;
            strings[10] = s11;
        }else if(size == 12){
            String s1 = getNextMonth(time);
            String s2 = getNextMonth(s1);
            String s3 = getNextMonth(s2);
            String s4 = getNextMonth(s3);
            String s5 = getNextMonth(s4);
            String s6 = getNextMonth(s5);
            String s7 = getNextMonth(s6);
            String s8 = getNextMonth(s7);
            String s9 = getNextMonth(s8);
            String s10 = getNextMonth(s9);
            String s11 = getNextMonth(s10);
            String s12 = getNextMonth(s11);
            strings[0] = s1;
            strings[1] = s2;
            strings[2] = s3;
            strings[3] = s4;
            strings[4] = s5;
            strings[5] = s6;
            strings[6] = s7;
            strings[7] = s8;
            strings[8] = s9;
            strings[9] = s10;
            strings[10] = s11;
            strings[11] = s12;
        }
        return strings;
    }

}
